var queryParam = {};
var totalPage = 1; // 总页数
var totalCount = 0; // 数据总数
queryParam.pageNo = 1;
queryParam.pageSize = 10;

$(function ($) {
    getInfoList();
    //首页
    $("#first_a").click(function(){
        queryParam.pageNo = 1;
        if($(this).attr("name") == "first_enable"){
            $("#pageInput").val("");
            getInfoList();
        }
    });
    //上一页
    $("#prev_a").click(function(){
        if(queryParam.pageNo == 1){
            layer.msg("已经是首页了！",{icon: 0});
        } else {
            queryParam.pageNo = queryParam.pageNo - 1;
            if($(this).attr("name") == "prev_enable"){
                $("#pageInput").val("");
                getInfoList();
            }
        }
    });
    //下一页
    $("#next_a").click(function(){
        if(queryParam.pageNo == totalPage){
            layer.msg("已经是末页了！",{icon: 0});
        } else {
            queryParam.pageNo = queryParam.pageNo + 1;
            if($(this).attr("name") == "next_enable"){
                $("#pageInput").val("");
                getInfoList();
            }
        }
    });
    //末页
    $("#last_a").click(function(){
        queryParam.pageNo = totalPage;
        if($(this).attr("name") == "last_enable"){
            $("#pageInput").val("");
            getInfoList();
        }
    });
    //输入页面序号，页面跳转
    $("#pageInputSubmit").click(function(){
        var pageInput = $("#pageInput").val();
        if(pageInput != undefined && pageInput != null && pageInput<=totalPage && pageInput>0){
            queryParam.pageNo = parseInt(pageInput);
            getInfoList();
        } else if(pageInput<=0 || pageInput>totalPage){
            layer.msg("页面超限，请重新输入！",{icon: 2});
            $("#pageInput").val("");
        }
    });
    $("select").change(function(){
        queryParam.pageSize = parseInt($(this)[0].value);
        getInfoList();
    });
});


function getInfoList(){
    console.log(JSON.parse(JSON.stringify(queryParam)));
    $.ajax({
        url: '/money/querylist',
        data:JSON.parse(JSON.stringify(queryParam)),
        type: 'get',
        cache: false,
        success: function(data) {
            console.log(data);
            totalCount = data.result.total;
            totalPage = data.result.pages;
            $("#totalCountHtml").html(totalCount);
            $("#pageInforHtml").html(queryParam.pageNo + "/" + totalPage);
            changePageButton();
            list = data.result.records;
            var infoHtml = "";
            for(var i = 0; i < list.length; i++){
                infoHtml += "<tr>"+
                                "<td>"+ list[i].sequence +"</td>"+
                                "<td>"+ list[i].name +"</td>"+
                                "<td>"+ list[i].phone +"</td>"+
                                "<td>"+ list[i].money/100 + "元" +"</td>"+
                                "<td>"+ list[i].payTime +"</td>"+
                                "<td>"+ list[i].sequence +"</td>"+
                            "</tr>";
            }
            $("#infoHtml").html(infoHtml);
        },
        error: function(xhr) {
        }
    });
}


//分页四个按钮的变化
function changePageButton(){
    if(totalPage == 1){
        $("#first_a").css({color:"#d0d0d0"});
        $("#first_a").attr("name","first_disable");
        $("#prev_a").css({color:"#d0d0d0"});
        $("#prev_a").attr("name","prev_disable");
        $("#next_a").css({color:"#d0d0d0"});
        $("#next_a").attr("name","next_disable");
        $("#last_a").css({color:"#d0d0d0"});
        $("#last_a").attr("name","last_disable");
    }else{
        if(queryParam.pageNo == 1){
            $("#first_a").css({color:"#d0d0d0"});
            $("#first_a").attr("name","first_disable");
            $("#prev_a").css({color:"#d0d0d0"});
            $("#prev_a").attr("name","prev_disable");
            $("#next_a").css({color:"#3399d5"});
            $("#next_a").attr("name","next_enable");
            $("#last_a").css({color:"#3399d5"});
            $("#last_a").attr("name","last_enable");
        }else if(queryParam.pageNo == totalPage){
            $("#first_a").css({color:"#3399d5"});
            $("#first_a").attr("name","first_enable");
            $("#prev_a").css({color:"#3399d5"});
            $("#prev_a").attr("name","prev_enable");
            $("#next_a").css({color:"#d0d0d0"});
            $("#next_a").attr("name","next_disable");
            $("#last_a").css({color:"#d0d0d0"});
            $("#last_a").attr("name","last_disable");
        }else{
            $("#first_a").css({color:"#3399d5"});
            $("#first_a").attr("name","first_enable");
            $("#prev_a").css({color:"#3399d5"});
            $("#prev_a").attr("name","prev_enable");
            $("#next_a").css({color:"#3399d5"});
            $("#next_a").attr("name","next_enable");
            $("#last_a").css({color:"#3399d5"});
            $("#last_a").attr("name","last_enable");
        }
    }
}